package com.misty.fly_weight.client1;

import org.junit.Test;

public class Client {
    private static final String[] departments = {"RD", "PM", "QA", "BD"};

    @Test
    public void demo() {
        for (int i = 0; i < 10; i++) {
            String department = departments[(int) (Math.random() * departments.length)];
            Manager manager = (Manager) EmployeeFactory.getManager(department);
            manager.report();
        }
    }

    //享元模式的例子测试,小于127 的使用享元模式，大于范围的重新创建
    // if (i >= IntegerCache.low && i <= IntegerCache.high)
    //            return IntegerCache.cache[i + (-IntegerCache.low)];
    //        return new Integer(i);
    @Test
    public void demo2() {
        Integer a = Integer.valueOf(127);
        Integer b = 127;

        Integer c = Integer.valueOf(128);
        Integer d = 128;

        System.out.println("a == b ? " + (a == b));
        System.out.println("c == d ? " + (c == d));

    }
}
